﻿Imports System.IO

Public Class Fächer
    Dim Daten As XML_bearbeiten = New XML_bearbeiten
   
    Private Sub loading()
        ListBox1.Items.Clear()
        TextBox1.Text = ""

        Dim i As Integer
        For i = 0 To Daten.daten.MAX_FACH
            If Daten.daten.Fächer(i) Is Nothing Then
            Else
                ListBox1.Items.Add(Daten.daten.Fächer(i).typ + ": " + Daten.daten.Fächer(i).name)
            End If
        Next
    End Sub


    Private Sub Fächer_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Daten.XMLReader()
        loading()

    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim Fach_k As Fächer_Class = New Fächer_Class
        Fach_k.Fach(TextBox1.Text, "Leistungskurs")
        Daten.daten.addFach(Fach_k)
        loading()

    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        Dim Fach_k As Fächer_Class = New Fächer_Class
        Fach_k.Fach(TextBox1.Text, "Grundkurs")
        Daten.daten.addFach(Fach_k)
        loading()
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Daten.XMLWriter(Daten)
        MsgBox("Änderungen erfolgreich übernommen!")
        Notenberechner1.loading()
        Me.Close()
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim i As Integer
        For i = 0 To Daten.daten.FächerAnz - 1
            If i = ListBox1.SelectedIndex Then
                Daten.daten.Fächer(i) = Nothing
                Daten.daten.FächerAnz = Daten.daten.FächerAnz - 1
            End If
        Next
        Daten.XMLWriter(Daten)
        Daten = New XML_bearbeiten
        Daten.XMLReader()
        loading()
    End Sub
End Class